package com.wc5818.wcImageDetail.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wc5818.common.AjaxResult;
import com.wc5818.wcCarInfos.entity.WcCarInfos;
import com.wc5818.wcCarInfos.mapper.WcCarInfosMapper;
import com.wc5818.wcImageDetail.entity.WcImgDetail;
import com.wc5818.wcImageDetail.mapper.WcImgDetailMapper;
import com.wc5818.wcImgPath.entity.WcImgPath;
import com.wc5818.wcImgPath.mapper.WcImgPathMapper;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 图片详情表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-03-20
 */
@RestController
@RequestMapping("/wcImageDetail")
public class WcImgDetailController {
    @Autowired
    WcImgDetailMapper wcImgDetailMapper;

    @Autowired
    WcImgPathMapper wcImgPathMapper;

    @PostMapping("/createNew")
    public Object createNew(@RequestBody WcImgDetail[] list) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);

        for (WcImgDetail wcImgDetail: list
             ) {
            if(wcImgDetail.getId() == null) {
                wcImgDetailMapper.insert(wcImgDetail);
            }

            WcImgPath wcImgPath = new WcImgPath();
            // 身份证
            if (wcImgDetail.getTypeId().equals(1))
                wcImgPath.setSfz1("1");
            // 驾驶证
            if (wcImgDetail.getTypeId().equals(2))
                wcImgPath.setJsz1("1");
            // 银行卡
            if (wcImgDetail.getTypeId().equals(3))
                wcImgPath.setYhk("1");
            // 征信授权书
            if (wcImgDetail.getTypeId().equals(4))
                wcImgPath.setZxsqs("1");
            // 征信授权书签字照
            if (wcImgDetail.getTypeId().equals(5))
                wcImgPath.setZxsqname("1");
            // 手持征信授+身份证照
            if (wcImgDetail.getTypeId().equals(6))
                wcImgPath.setScsfzx("1");
            // 手持身份证照
            if (wcImgDetail.getTypeId().equals(7))
                wcImgPath.setScsf("1");
            // 投保单
            if (wcImgDetail.getTypeId().equals(8))
                wcImgPath.setTbd("1");
            // 投保单签字照
            if (wcImgDetail.getTypeId().equals(9))
                wcImgPath.setTbdqz("1");
            // 投保声明
            if (wcImgDetail.getTypeId().equals(10))
                wcImgPath.setTbsm("1");
            // 挂靠协议
            if (wcImgDetail.getTypeId().equals(11))
                wcImgPath.setGkxy1("1");
            // 购车合同
            if (wcImgDetail.getTypeId().equals(12))
                wcImgPath.setGcht("1");
            // 推荐函
            if (wcImgDetail.getTypeId().equals(13))
                wcImgPath.setTjh("1");
            // 担保函
            if (wcImgDetail.getTypeId().equals(14))
                wcImgPath.setDbh("1");
            // 首付款凭证
            if (wcImgDetail.getTypeId().equals(15))
                wcImgPath.setSfkpz("1");
            // 客户告知书
            if (wcImgDetail.getTypeId().equals(16))
                wcImgPath.setKhgzs("1");
            // 代扣授权委托书
            if (wcImgDetail.getTypeId().equals(17))
                wcImgPath.setDksqwts("1");
            // 账户查询授权书
            if (wcImgDetail.getTypeId().equals(18))
                wcImgPath.setZhcxsqs("1");
            // 租赁合同
            if (wcImgDetail.getTypeId().equals(19))
                wcImgPath.setZpht1("1");
            // 抵押合同
            if (wcImgDetail.getTypeId().equals(20))
                wcImgPath.setDyht1("1");
            // 月供确认书
            if (wcImgDetail.getTypeId().equals(21))
                wcImgPath.setYgqrs("1");
            // 委托付款书
            if (wcImgDetail.getTypeId().equals(22))
                wcImgPath.setWtfks("1");
            // 其他资料
            if (wcImgDetail.getTypeId().equals(23))
                wcImgPath.setQita("1");

            if (wcImgPathMapper.update(wcImgPath, new QueryWrapper<WcImgPath>().eq("id", wcImgDetail.getImgId())) >= 0)
                ajaxResult.setSuccess(true);

        }

        return ajaxResult;
    }

    @DeleteMapping("deleteById")
    public Object deleteById(String id) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);

        if(wcImgDetailMapper.deleteById(id) > 0)
            ajaxResult.setSuccess(true);

        return ajaxResult;
    }

    @GetMapping("queryByImgId")
    public Object queryByImgId(String imgId, String typeId) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);

        List list = wcImgDetailMapper.selectList(new QueryWrapper<WcImgDetail>().eq("imgId", imgId).eq("typeId", typeId));
        if(list != null && list.size() > 0) {
            ajaxResult.setSuccess(true);
            ajaxResult.setData(list);
        }

        return ajaxResult;
    }


}
